package com.shzg.im.web.binder;

import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.util.StringUtils;

public class CustomLongDateEditor extends CustomDateEditor {

    public CustomLongDateEditor(DateFormat dateFormat, boolean allowEmpty) {
        super(dateFormat, allowEmpty);
    }

    public CustomLongDateEditor() {
        super(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), false);
    }

    @Override
    public void setAsText(String longStr) throws IllegalArgumentException {
        if (StringUtils.isEmpty(longStr)
                || StringUtils.hasLength(longStr) == false) {
            setValue(null);
        } else {
            long timeLong = Long.parseLong(longStr);
            setValue(new Date(timeLong));
        }

    }

}
